/**
 * 怪物类(鱼)
 */

class Monster extends Laya.Sprite {
    //鱼的类型
    public type : number;
    //移动方向(0-左 1-右)
    private moveDir : number;
    //移动速度
    private speed : number;
    //碰撞半径
    public collideRadius : number;

    constructor() {
        super();
    }

    //初始化鱼 type-鱼的类型 isMoveUp-鱼钩是否处于上升状态
    Init(type:number, isMoveUp:boolean) : void {
        //随机速度
        this.speed = ComFun.GetRandomInt(ComCfg.MinSpeed, ComCfg.MaxSpeed);
        this.collideRadius = 25;
        //随机方向
        this.type = type;
        this.moveDir = ComFun.GetRandomInt(0, 1);
        let strDir = "";
        if(this.moveDir != 0){
            strDir = "r"
        }
        //随机初始x坐标
        let randX = ComFun.GetRandomInt(0, Laya.stage.width);
        //设置初始y坐标
        let initY = 0;
        if(!isMoveUp){
            //鱼钩下降
            initY = Laya.stage.height;
        }
        else{
            //鱼钩上升
            initY = -50;
        }

        let strUrl = "ui/fish" + strDir + this.type + ".png";
        this.loadImage(strUrl, 0, 0, 70, 50);
        this.pos(randX, initY);
        this.pivotX = 25;
		this.pivotY = 15;
    }

    //鱼的移动(左右和上下)
    Move(isMoveUp:boolean) : void {
        let moveX = 0;
        let moveY = 0;
        if(this.moveDir == 0){
            moveX = -1 * this.speed;
        }
        else{
            moveX = this.speed;
        }
        if(!isMoveUp){
            moveY = -1 * ComCfg.DownPixel;
        }
        else{
            moveY = ComCfg.UpPixel;
        }

        this.x = this.x + moveX;
        this.y = this.y + moveY;
    }
}